/* 
 * File:   prepare_connection.h
 * Author: james
 *
 * Created on 2011年4月2日, 下午1:53
 */

#ifndef PREPARE_CONNECTION_H
#define	PREPARE_CONNECTION_H

#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include "net_client.h"

namespace edm
{
    namespace prepare
    {
        //! prepare connection, self maintain retry connect... 
        class prepare_connection_t: public edm::network::net_client_t
        {
            enum {RETRY_LOOP_MAX = 10};
        public:
            prepare_connection_t(const std::string& host, const std::string& port);
            ~prepare_connection_t();
            
            void stop(bool force);
            void callback_connect(edm::network::connection_ptr_t c);
            void callback_error(edm::network::connection_ptr_t c);
        private:
            void retry_connect(edm::network::connection_ptr_t c);
        private:
            //! retry policy
            long  m_retry_interval;
            //! retry counts
            int   m_retry_counts;
            //! force flag stop
            bool  m_force;
            //! the timer for loop checking timedout task
            boost::asio::deadline_timer m_timer;
        };

    }
}


#endif	/* PREPARE_CONNECTION_H */

